//
//  HSYPictureHelper.m
//  高仿暴走斗图
//
//  Created by huangsongyao on 16/3/4.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "HSYPictureHelper.h"
#import "UIImageView+WebCache.h"

static HSYPictureHelper *pictureHelper;

@implementation HSYPictureHelper

+ (instancetype)shareInstance {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        pictureHelper = [HSYPictureHelper new];
    });
    return pictureHelper;
}

+ (void)loadWebImageWithImageView:(UIImageView *)imageView
                              scr:(NSString *)scr
                          imgSize:(kWebImageSizeType)imgSize
             placeholderImageType:(kPlaceholderImageType)placeholderImageType {
    
    NSURL *url = ImageUrl(scr, imgSize);
    UIImage *image = CREATE_IMG([HSYPictureHelper checkPlaceholderImageWithPlaceholderImageType:placeholderImageType]);
    
    [imageView sd_setImageWithURL:url
                 placeholderImage:image
                          options:SDWebImageRefreshCached];     //设置为如果当前图片链接有新的图片更新，就放弃缓存加载新图
}

+ (NSString *)checkPlaceholderImageWithPlaceholderImageType:(kPlaceholderImageType)placeholderImageType {
    
    NSString *palaceholder = nil;
    switch (placeholderImageType) {
        case kPlaceholderImageTypeAvatar:
            palaceholder = @"";
            break;
        case kPlaceholderImageTypeFissionImg:
            palaceholder = @"";
            break;
            
        default:
            break;
    }
    return palaceholder;
}

static NSURL *ImageUrl(NSString * scr,kWebImageSizeType imgSize) {
    
    NSURL *url = [NSURL URLWithString:[[NSString stringWithFormat:@"%lu", (unsigned long)imgSize] stringByAppendingString:scr]];
    return url;
//    return [NSURL URLWithString:scr];
}

@end
